package com.hsy.linemoney.apiservice;

import com.deparse.dpframe.tools.utils.DPGsonUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2016/12/20.
 */

public class AddReferenceId extends BasicService<JSONArray> {
    private static Object checkNull(Object object) {
        return object == null ? "" : object;
    }

    //添加推荐人
    public void addReferenceId(
            long companyId, String userId, String referenceId, final Callback<AddReferenceIdJson> callback) {
//                            companyId: 20155,
//                            userId: ,
//                            referenceId: ,
//
        try {
            JSONObject _result = new JSONObject();
            _result.put("companyId", companyId);
            _result.put("userId", userId);
            _result.put("referenceId", referenceId);
            String api = "/LmRegistration-portlet.account/addReferenceId";
            invoke(0, api, _result, new Callback<JSONArray>() {
                @Override
                public void onSuccess(int what, JSONArray result) {
                    if (null != callback) {
                        try {
                            callback.onSuccess(what, DPGsonUtil.fromJson(result.get(0).toString(), AddReferenceIdJson.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            callback.onError(what, 0, e.getMessage(), e);
                        }
                    }
                }

                @Override
                public void onError(int what, int type, String msg, Exception e) {
                    if (null != callback) {
                        callback.onError(what, 0, e.getMessage(), e);
                    }
                }
            }, false);
        } catch (JSONException e) {
            e.printStackTrace();
            if (null != callback) {
                callback.onError(0, 0, e.getMessage(), e);
            }
        }
    }

    public class AddReferenceIdJson {
        private Status status;

        public void setStatus(Status status) {
            this.status = status;
        }

        public Status getStatus() {
            return this.status;
        }

        public class Status {
            private String message;

            private int code;

            public void setMessage(String message) {
                this.message = message;
            }

            public String getMessage() {
                return this.message;
            }

            public void setCode(int code) {
                this.code = code;
            }

            public int getCode() {
                return this.code;
            }

        }

    }
}
